package ro.qi.framework.sys.db.util;

import java.sql.Types;
/**
 * Represents a field with a NULL Value. An instance of this
 * class is used to pass NULL values to the stored procedure
 * using the DB API
 *
 * @author Srinivas
 */
public class NullParam {

	int sqlType; // one of types defined in java.sql.Types class

	public NullParam(String pJavaType) throws UnsupportedTypeException {
		getSQLType(pJavaType);
	}

	private void getSQLType(String pJavaType) throws UnsupportedTypeException {
		if (pJavaType.equals(DBConnectionUtil.BIGDECIMAL_TYPE)) {
	    	sqlType = Types.BIGINT;
	    } else if (pJavaType.equals(DBConnectionUtil.BOOL_TYPE)) {
	     	sqlType = Types.BIT;
	    } else if (pJavaType.equals(DBConnectionUtil.DATE_TYPE)) {
	     	sqlType = Types.DATE;
	    } else if (pJavaType.equals(DBConnectionUtil.DOUBLE_TYPE)) {
	     	sqlType = Types.DOUBLE;
	    } else if (pJavaType.equals(DBConnectionUtil.FLOAT_TYPE)) {
	     	sqlType = Types.FLOAT;
	    } else if (pJavaType.equals(DBConnectionUtil.INT_TYPE)) {
	     	sqlType = Types.NUMERIC;
	    } else if (pJavaType.equals(DBConnectionUtil.LONG_TYPE)) {
	     	sqlType = Types.NUMERIC;
	    } else if (pJavaType.equals(DBConnectionUtil.SHORT_TYPE)) {
	     	sqlType = Types.SMALLINT;
	    } else if (pJavaType.equals(DBConnectionUtil.STRING_TYPE)) {
	     	sqlType = Types.VARCHAR;
	    } else if (pJavaType.equals(DBConnectionUtil.TIME_TYPE)) {
	     	sqlType = Types.TIME;
	    } else if (pJavaType.equals(DBConnectionUtil.TIMESTAMP_TYPE)) {
	     	sqlType = Types.TIMESTAMP;
	    } else {
	      	throw new UnsupportedTypeException("Unsupported data type: " + pJavaType);
	     }
	}

	public int getType() {
		return sqlType;
	}

}

